package com.wf.service.impl;

import com.wf.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.internet.MimeMessage;

/**
 * @author mpk
 * @since 2024/9/10 09:25:32
 */
@Service
public class JavaMailServiceImpl implements SendMailService {


    @Autowired
    JavaMailSender javaMailSender;


    @Override
    public void sendEmailCode(String email, String code) {

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("1613828539@qq.com"+"(优享租)");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("邮箱登录");
        simpleMailMessage.setText("您的验证码为："+code);
        javaMailSender.send(simpleMailMessage);
    }
    @Override
    public void sendEmailHTML(String email, String text) {
            try {
                MimeMessage message = javaMailSender.createMimeMessage();
                MimeMessageHelper helper = new MimeMessageHelper(message);
                helper.setFrom("1613828539@qq.com"+"(马朋坤)");
                helper.setTo(email);
                helper.setSubject("项目进度");
                helper.setText(text,true); //此处设置正文支持html解析
                javaMailSender.send(message);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    @Override
    public void sendRemindersEmail(String email, String text) {
        try {
            MimeMessage message = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message);
            helper.setFrom("2323741953@qq.com"+"(悠享公寓租赁平台)");
            helper.setTo(email);
            helper.setSubject("您有未缴费订单请及时处理");
            helper.setText(text); //此处设置正文支持html解析
            javaMailSender.send(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

